/*
 * $$Id: FogotPassAction.java,v 1.3 2005/06/07 12:32:29 bel70 Exp $$
 *
 * ***** BEGIN LICENSE BLOCK *****
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License
 * at http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and
 * limitations under the License.
 *
 * The Original Code is jforum forum code.
 *
 * The Initial Developer of the Original Code is the JResearch, Org.
 * Portions created by the Initial Developer are Copyright (C) 2004
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *              Dmitry Belov <bel@jresearch.org>
 *
 * ***** END LICENSE BLOCK ***** */
package com.jred.jforum.actions.user;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.util.MessageResources;

import com.jred.jforum.IConst;
import com.jred.jforum.actions.BaseAction;
import com.jred.jforum.actions.common.TDDispatchAction;
import com.jred.jforum.beans.user.User;
import com.jred.jforum.exception.SystemException;
import com.jred.jforum.forms.FogotPasswordForm;
import com.jred.jforum.service.UserService;

/**
 * DOCUMENT ME!
 * 
 * @author $author$
 * @version $Revision: 1.3 $
 */
public final class UserManagerAction extends TDDispatchAction {
	
	private static String ENABLE_FORUM_SIGN_ON = "Y";
	private static String ENABLE_AUTO_LOGIN = "Y";

	public ActionForward register(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws SystemException {
		return (mapping.findForward("register"));
	}

	public ActionForward forgotPass(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws SystemException {
		if (IConst.VALUES.FALSE.equals(ENABLE_FORUM_SIGN_ON)) {
			return (mapping.findForward("jforum-denied"));
		}

		// Extract attributes we will need
		HttpSession session = request.getSession();
		ActionErrors errors = new ActionErrors();


		UserService forumService = (UserService) ctx.getBean("userService");

		FogotPasswordForm fpForm = (FogotPasswordForm) form;

		User updateduser = null;//forumService.setNewPassword(fpForm.getEmail(), fpForm
				//.getUid());

		if (updateduser.getStatus() == 0) {
			errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
					"user.EMERROR"));
		} else {
			/*
			 * MailMessage(String messagetext, String subject, String
			 * addrfrom, String namefrom, String addrto, String nameto)
			 */
			MessageResources messages = getResources(request);

			/*
			 * {0} - login {1} - new password {2} - site url {3} - site name
			 */
			StringBuffer siteUrl = new StringBuffer();
			siteUrl.append(request.getServerName());
			siteUrl.append(":");
			siteUrl.append(request.getServerPort());
			siteUrl.append(request.getContextPath());
			siteUrl.append("/jforum");
			siteUrl.append("/");

			Object[] messArgs = new Object[] { updateduser.getName(),
					updateduser.getPassword(), siteUrl.toString(),
					"jforum" };

		
		}

		// Report any errors we have discovered back to the original form
		if (!errors.isEmpty()) {
			saveErrors(request, errors);
			return (mapping.getInputForward());
		}

		return (mapping.findForward("welcome"));
	}
}